<link rel="stylesheet" href="/stylesheets/biz/auth/updatemanager.css" />

<div class="">

    <div class="row">
        <div class="div-row1">
                <a href="/auth/adminlist" class="a-row1" >管理员列表</a><span class="divider">/</span></li>
                <label class="label-row1">编辑管理员</label>
        </div>
    </div>


    <div class="row">
        <form class="form-class" id="addmana-form">

                <div class="div-rows">
                    <label><span style="visibility: hidden">隐藏</span><font color="red">*</font>ID：</label>
                    <span class=""><%= admin.user_id%></span>
            </div>
            <div class="div-row2">
                <label><span style="visibility: hidden">藏</span><font color="red">*</font>用户名：</label>
                <span class=""><%= admin.login_name%></span>
            </div>

            <div class="div-row4">
                <label><span style="visibility: hidden">藏</span><font color="red">*</font>手机号：</label>
                <span class=""><%= admin.mobile%></span>
            </div>


            <div class="div-row5">
                <font color="red">*</font>
                <label>邮箱地址：</label>
                <span class=""><%= admin.email%></span>
            </div>



            <div class="div-row4">
                <label><span style="visibility: hidden">藏</span><font color="red">*</font>新密码：</label>
                <input class="input-class" name="password" placeholder="请输入新密码">
                </input>
               <font color="#a9a9a9">若留空，密码保持不变</font>

            </div>

            <div class="div-row5">
                <font color="red">*</font>
                <label>确认密码：</label>
                <input class="input-class" name="password2" placeholder="请再次输入新密码">
                </input>
            </div>

            <div class="div-row5">
                <font color="red">*</font>
                <label>角色选择：</label>
                <div id="sel" style="width:200px;margin:-40px;margin-left:75px;">
                    <input type="hidden" id="role_id" name="role_id" data-rules="{required:true}">
                </div>
            </div>


            <div class="div-btn">
                <a class="btn-class1 btn btn-green" id="smtBtn"> 确定提交 </a>
            </div>

        </form>


    </div>



</div>

<script type="text/javascript">
    KISSY.use(['io','dom','bui/form','bui/select'],function(S,IO,DOM,Form,Select){
        var user_id = '<%= admin.user_id%>';
        IO.post("/api/getUserRole",{},function(roles) {
            var items = [];
            S.each(roles, function(role){
                var item = {};
                item.text = role.role_text;
                item.value = role.role_id;
                items.push(item);
            });

            var select = new Select.Select({
                render:'#sel',
                valueField:'#role_id',
                items:items
            });
            select.render();
            //默认选择地一个
            select.setSelectedValue(<%= admin.role_id%>);
        });

        //表单验证
        var valifForm = new Form.Form({
            srcNode:'#addmana-form'
        }).render();
        $("#smtBtn").on('click',function() {//确定提交事件
            var formdata = {};
            var form = $("#addmana-form").all('input[name],textarea[name], select[name]');
            form.each(function(item, index) {
                formdata[$(item).attr('name')] = $(item).val();
            });
            formdata.user_id = user_id;
            console.log(formdata);
            if(valifForm.isValid()) {//验证通过则提交表单
                IO.post("/api/updateAdminById",formdata,function(data) {
                    window.parent._Alert(data.msg,data.code==0?'success':'error');
                    if(data.code == 0){
                        parent.$("#dmp-iframe").attr('src','/auth/adminlist');
                    }
                },"json");
            }
        });

    });
</script>